package com.huiqiao.lesson8.mybatis.controller;

import lombok.Data;

public class BaseController {


    public AppResponse success() {
        AppResponse response = new AppResponse(200, "操作成功", null);
        return response;
    }

    public AppResponse success(Object data) {
        AppResponse response = new AppResponse(200, "操作成功", data);
        return response;
    }

    public AppResponse success(Object data, String message) {
        AppResponse response = new AppResponse(200,  message, data);
        return response;
    }

    public AppResponse fail() {
        return new AppResponse(500, "操作失败", null);
    }

    public AppResponse fail(String message) {
        return new AppResponse(500, message, null);
    }

    public AppResponse fail(int code, String message) {
        return new AppResponse(code, message, null);
    }

    @Data
    public static class AppResponse<T> {
        int code;
        String message;
        T data;

        public AppResponse(int code, String message, T data) {
            this.code = code;
            this.message = message;
            this.data = data;
        }
    }
}
